#include<stdio.h>
#include<windows.h>

typedef struct Play//定义结构体变量
{
	int number;
	int out;
	struct Play *next;
} Pl;

int main()
{
	int i = 1,j = 1,count=0;
	Pl p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, *head, *pointer;
	p1.number = 1;   //>>>>//
	p2.number = 2;  //编号//
	p3.number = 3; //<<<<//
	p4.number = 4;
	p5.number = 5;
	p6.number = 6;
	p7.number = 7;
	p8.number = 8;
	p9.number = 9;
	p10.number = 10;
	p11.number = 11;
	p12.number = 12;
	p13.number = 13;

	head = &p1;
	p1.next = &p2;
	p2.next = &p3;
	p3.next = &p4;
	p4.next = &p5;
	p5.next = &p6;
	p6.next = &p7;
	p7.next = &p8;
	p8.next = &p9;
	p9.next = &p10;
	p10.next = &p11;
	p11.next = &p12;
	p12.next = &p13;
	p13.next = malloc(sizeof(int));
	pointer = head;

	for (i = 0; i < 13; i++)//第一轮报数
	{
		(*pointer).out = j++;
		if (j == 4)
		{
			j = 1;
		}
		pointer = pointer->next;//指向下一个

	}

	i = 1;
	pointer = head;//再次初始化

	do//处理数据
	{
		printf_s("第%d位是报数%d\n", (*pointer).number, (*pointer).out);

		if ((*pointer).out != 0)
		{
			(*pointer).out = i++;
			if ((*pointer).out == 3)
			{
				(*pointer).out = 0;
				i = 1;

			}
		}
		
		if ((*pointer).number == 13)
		{
			pointer = head;
		}
		else
		{
			pointer = pointer->next;//指向下一个
		}

		if ((*pointer).out == 0)
		{
			count++;//这个用来计数连续的0，但连续有12个0时，说明只剩一人
			if (count == 13)//但实际上count++为后加型，所以这里应为12+1
				break;
		}
		else
		{
			count = 0;
		}

	} while (1);
	
	printf_s("最后剩下的学生是第%d位\n", (*pointer).number);

	system("pause");
	return 0;
}